﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NMLX_Data_Management
{
    public partial class QCQuery : Form
    {
        public QCQuery()
        {
            InitializeComponent();
        }

        private void QCQuery_Load(object sender, EventArgs e)
        {
            Query(" where 1=1  and qcr <>''");
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            string where = "where 1=1 and   qcr like '%" + toolStripTextBox1.Text + "%' and qcr <>''";
            Query(where);
        }

        private void Query(string where)
        {
            string sql = string.Format(" select projectname,ProgramName,qcr,qcdate from projectdetail {0} ", where);
            try
            {
                DataSet ds = new DataSet();
                ds = NMLX.DBUtility.DbHelperOleDb.Query(sql);
                dataGridView1.DataSource = ds.Tables[0];
                dataGridView1.Columns[0].HeaderCell.Value = "电厂名称";
                dataGridView1.Columns[1].HeaderCell.Value = "程序名称";
                dataGridView1.Columns[2].HeaderCell.Value = "签出人";
                dataGridView1.Columns[3].HeaderCell.Value = "签出时间";
                this.dataGridView1.Refresh();
                //this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Gray;
                this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString() == "\r")
            {
                string where = "where 1=1 and   qcr like '%" + toolStripTextBox1.Text + "%' and qcr <>''";
                this.toolStripTextBox1.Text = "";
                Query(where);

            }
        }
    }
}
